//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbGiangVien_NgoaiNgu
    {
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbGiangVien_NgoaiNgu_SelectAll_TAM", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbGiangVien_NgoaiNgu_SelectTop", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static bool KiemTraDuLieu(ETbGiangVien_NgoaiNgu GVNN)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaGV", GVNN.MaGV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu", GVNN.MaNgoaiNgu);


            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbGiangVienNN_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public static bool KiemTraDuLieu1(ETbGiangVien GV)
        {
            SqlParameter[] pr = new SqlParameter[4];
            pr[0] = new SqlParameter(@"MaGV", GV.MaGV);
            pr[1] = new SqlParameter(@"MaDonVi", GV.MaDonVi);
            pr[2] = new SqlParameter(@"MaChucVu", GV.MaChucVu);
            pr[3] = new SqlParameter(@"SoCMT", GV.SoCMT);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbGiangVien_KiemTraDuLieu1", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }

        //-----------------------------------------------------------//
        public static DataTable SearchTenGiangVienNN(String GV)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenGV", GV);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbGiangVienNN_Search", pr);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbGiangVien_NgoaiNgu OTbGiangVien_NgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[5];
            pr[0] = new SqlParameter(@"MaGV", OTbGiangVien_NgoaiNgu.MaGV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu", OTbGiangVien_NgoaiNgu.MaNgoaiNgu);
            pr[2] = new SqlParameter(@"NgayCap", OTbGiangVien_NgoaiNgu.NgayCap);
            pr[3] = new SqlParameter(@"NoiCap", OTbGiangVien_NgoaiNgu.NoiCap);
            pr[4] = new SqlParameter(@"TrangThai", OTbGiangVien_NgoaiNgu.TrangThai);

            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbGiangVien_NgoaiNgu_Insert", pr);
        }
      
//-----------------------------------------------------------//
        public static void Update(ETbGiangVien_NgoaiNgu OTbGiangVien_NgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[4];
            pr[0] = new SqlParameter(@"MaGV", OTbGiangVien_NgoaiNgu.MaGV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu", OTbGiangVien_NgoaiNgu.MaNgoaiNgu);
            pr[2] = new SqlParameter(@"NgayCap", OTbGiangVien_NgoaiNgu.NgayCap);
            pr[3] = new SqlParameter(@"NoiCap", OTbGiangVien_NgoaiNgu.NoiCap);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbGiangVien_NgoaiNgu_Update", pr);
        }
       
            //-----------------------------------------------------------//
        public static void Update1(ETbGiangVien_NgoaiNgu OTbGiangVien_NgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TrangThai", OTbGiangVien_NgoaiNgu.TrangThai);
         
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbGiangVien_NgoaiNgu_Update_TT", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(string MaGV,int MaNgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaGV",MaGV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu",MaNgoaiNgu);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbGiangVien_NgoaiNgu_Delete", pr);
        }

        public static void DeleteByMaGV(string MaGV)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaGV", MaGV);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbGiangVien_NgoaiNgu_DeleteByMaGV", pr);
        }
        //
//-----------------------------------------------------------//
        public static ETbGiangVien_NgoaiNgu SelectByID(string MaGV, int MaNgoaiNgu)
        {
            ETbGiangVien_NgoaiNgu OTbGiangVien_NgoaiNgu = new ETbGiangVien_NgoaiNgu();
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaGV",MaGV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu",MaNgoaiNgu);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbGiangVien_NgoaiNgu_SelectByID", pr);
            if (idr.Read())
              OTbGiangVien_NgoaiNgu = GetOneTbGiangVien_NgoaiNgu(idr);
            idr.Close();
            idr.Dispose();
            return OTbGiangVien_NgoaiNgu;
        }
        public static DataTable SelectByMaGV(string MaGV)
        {
            ETbGiangVien_NgoaiNgu OTbGiangVien_NgoaiNgu = new ETbGiangVien_NgoaiNgu();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaGV",MaGV);            
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure,"TbGiangVien_NgoaiNgu_SelectByMaGV", pr);    
            return all;
        }

        
//-----------------------------------------------------------//
        private static ETbGiangVien_NgoaiNgu GetOneTbGiangVien_NgoaiNgu(IDataReader idr)
       {
            ETbGiangVien_NgoaiNgu OTbGiangVien_NgoaiNgu = new ETbGiangVien_NgoaiNgu();
                if (idr["MaGV"] != DBNull.Value)
                    OTbGiangVien_NgoaiNgu.MaGV = (string)idr["MaGV"];
                if (idr["MaNgoaiNgu"] != DBNull.Value)
                    OTbGiangVien_NgoaiNgu.MaNgoaiNgu = (int)idr["MaNgoaiNgu"];
                if (idr["NgayCap"] != DBNull.Value)
                    OTbGiangVien_NgoaiNgu.NgayCap = (DateTime)idr["NgayCap"];
                if (idr["NoiCap"] != DBNull.Value)
                    OTbGiangVien_NgoaiNgu.NoiCap = (string)idr["NoiCap"];
            return OTbGiangVien_NgoaiNgu;
       }
//-----------------------------------------------------------//
        public static bool TestByID(string MaGV, int MaNgoaiNgu)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaGV",MaGV);
            pr[1] = new SqlParameter(@"MaNgoaiNgu",MaNgoaiNgu);
            pr[2] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[2].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbGiangVien_NgoaiNgu_TestByID", pr);
            return Convert.ToBoolean(pr[2].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbGiangVien_NgoaiNgu> ListAll()
        {
            List<ETbGiangVien_NgoaiNgu> list = new List<ETbGiangVien_NgoaiNgu>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbGiangVien_NgoaiNgu_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbGiangVien_NgoaiNgu(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }

        public static List<ETbGiangVien_NgoaiNgu> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbGiangVien_NgoaiNgu> list = new List<ETbGiangVien_NgoaiNgu>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbGiangVien_NgoaiNgu_SelectAll", pr);
            while (idr.Read())
              list.Add(GetOneTbGiangVien_NgoaiNgu(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}